package com.hualan.service.b;

import com.hualan.entity.b.Shops;
import com.hualan.utils.ExecUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Map;
import java.util.Set;

@WebServlet(urlPatterns = {"/shop/addShop","/shop/querySearchShopList"})
public class ShopService extends HttpServlet {
    
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String sql = "INSERT INTO Shops (shopAddress,shopCity,shopDescribe,shopDistrict,shopImage,shopLatitude,shopLongitude,shopName,shopPhone,shopProvince,addTime) VALUES (?,?,?,?,?,?,?,?,?,?,NOW())";
        ArrayList<Object> params = new ArrayList<>();
        Map<String, String[]> parameterMap = req.getParameterMap();
        Set<String> set = parameterMap.keySet();

        for (String s : set) {
            params.add(parameterMap.get(s)[0]);
        }
        boolean b =(Boolean)  ExecUtil.execute(sql, params, req, true);
        if (b){
            resp.getWriter().write("新增成功");
        }else {
            resp.getWriter().write("失败");
        }
        try {
            ExecUtil.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
